var debugRefreshSignCount = 100;

$(document).on('click', '[debug-name="env"]', function(){
	//alert();
	var api_url = $('[debug-name="env"]:checked').val();
	api_url += '/'+$('[name="interface_path"]').val();
	$('[debug-name="api_url"]').val(api_url);
})
$(document).on('click', '#debugSubmit', function(){
	var url = $('[debug-name="api_url"]').val(), app_id = $('#debugAppid').html();
	var sign = $('[debug-name="api_sign"]').val();
	
	//判断请求方式
	var receive_type = $('[name="request_type"]:checked').val();
	//var post_data = '{';
	var post_data = {};
	var postType = 'get';
	$(".debug_params").each(function(index, element) {
		var param_name = $(this).attr('param-name');
		var param_value = $(this).val();
        switch(receive_type){
			case 'get':
				url += index == 0 ? '?' : '&';
				url += param_name + '=' + param_value;
				break;debugSubmit
			case 'post':
				//post_data += param_name + ':"' + param_value + '",';
				post_data[param_name] = param_value;
				postType = 'post';
				break;
			default:
				url += '/'+param_name;
				break;
		}
    });
	post_data = JSON.stringify(post_data);
	//必传参数
	//if(receive_type == 'post'){
//		post_data += '}';
//		post_data = post_data.replace(',}', '}');
//		//post_data = $.parseJSON(post_data);
//	}else{
//		post_data = '';
//	}
	url += url.indexOf('?') < 0 ? '?' : '&';
	url += 'appId=' + app_id;
	url += '&cls=' + $('[name="debugPlatform"]:checked').val();
	url += '&sign=' + sign;
	
	$("#debugInfos").html(url);
	$("#debugResult").html('Loading...');
	$.ajax({
		url: BASE_URI+"utils/send_post/",//提交的地址request_by_curl
		data: {url:encodeURIComponent(url), post_data:post_data},//提交的数据
		type: 'post',
		success: function(data) {
			var datas = $.parseJSON(data);
			var formatJson = new JSONFormat(datas);
			//alert(formatJson);
			$("#debugResult").html(formatJson.toString().replace(/\n/g, "<br>"));//
			//$("#debugResult").html(data);
		},
		error: function(err){
			//提交失败的信息
			alert("数据请求失败！");
		} 
	});
	return;
/*	$.ajax({
		url: url,//提交的地址
		data:post_data,//提交的数据
		type: postType,
		success: function(data) {
			var datas = $.parseJSON(data);
			var formatJson = new JSONFormat(datas);
			//alert(formatJson);
			$("#debugResult").html(formatJson.toString().replace(/\n/g, "<br>"));//
			//$("#debugResult").html(data);
		},
		error: function(err){
			//提交失败的信息
			alert("数据请求失败！");
		} 
	});*/

})
      


 
/*(function request_intercept(args){
    var $result_container = args[0],
        $result = args[1];
    $('form *[type="submit"]').bind('click', function(){
        var _form = $(this).parents('form'),
            _action = (_form.attr('action') || './'),
            _method = (_form.attr('method') || 'get').toLowerCase(),
            _params = {};
        _form.find('input[type="text"]').each(function(){
            var item = $(this);
            _params[item.attr('name')] = item.val();
        });
        $['get' == _method ? 'get' : 'post'](_action, _params, function(response){
            try{
                var j = new JSONFormat(JSON && JSON.parse ? JSON.parse(response) : eval('(' + response + ')'));
                $result.html(j.toString());
            }catch (e){
                $result.html($result.text(response).html());
            }
            $result_container.stop(true).animate({width:'50%'}, 'slow');
        });
        return false;
    });
})(create_result_contatiner());*/